set(PROJECT_NAME svgeditor)
set(BINARY_NAME qtsvg)
project (${PROJECT_NAME})

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP "Generated Files")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5 COMPONENTS Core Widgets Svg Concurrent)

include_directories(
	${xml_SOURCE_DIR}
)

# library
set (SOURCES
	"stdafx.h"

	"src/svgeditor.h"
	"src/svgeditor.cpp"

	"src/svgwidget.h"
	"src/svgwidget.cpp"

	"src/svgcanvas.h"
	"src/svgcanvas.cpp"

	"src/svgbottomtoolbar.h"
	"src/svgbottomtoolbar.cpp"

	"src/svgshape.h"
	"src/svgshape.cpp"

	"src/svgwriter.h"
	"src/svgwriter.cpp"

	"src/svgreader.h"
	"src/svgreader.cpp"

	"src/svgpalette.h"
	"src/svgpalette.cpp"

	"src/utils.h"
	"src/utils.cpp"

	"src/infowidget/svgextrainfowidget.h"
	"src/infowidget/svgextrainfowidget.cpp"
	"src/infowidget/svgcanvasinfowidget.h"
	"src/infowidget/svgcanvasinfowidget.cpp"
	"src/infowidget/svglineinfowidget.h"
	"src/infowidget/svglineinfowidget.cpp"
	"src/infowidget/widgets/svgpropinput.h"
	"src/infowidget/widgets/svgpropinput.cpp"
	"src/infowidget/widgets/svgcolorselector.h"
	"src/infowidget/widgets/svgcolorselector.cpp"

	"src/ui/mainwindow.ui"
	)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "code" FILES ${SOURCES})

# 将源代码添加到此项目的可执行文件。
add_library(${PROJECT_NAME} STATIC
	${SOURCES}
	)

target_link_libraries(${PROJECT_NAME}
	Qt5::Core 
	Qt5::Widgets
	Qt5::Svg
	Qt5::Concurrent 
	Microsoft.GSL::GSL
	xml
	)

# binary
add_executable (${BINARY_NAME}
	"src/main.cpp"
	"res/svg.qrc"
	)

target_link_libraries(${BINARY_NAME}
	${PROJECT_NAME}
	)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${BINARY_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE "./src")

target_precompile_headers(${PROJECT_NAME}
	PUBLIC
		"stdafx.h"
	)

# auto windeployqt
if (RUN_WINDEPLOYQT)
	# 自动运行 windeployqt
	# 参考: https://riptutorial.com/qt/example/24133/integrating-with-cmake
	get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
	get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
	find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
	add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
		COMMAND "${CMAKE_COMMAND}" -E
			env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
				"$<TARGET_FILE:${BINARY_NAME}>"
		COMMENT "Running windeployqt..."
	)
endif()

